package com.admin.commodity.controller;


import com.admin.commodity.pojo.MobileEndCommodity;
import com.admin.commodity.service.MobileEndCommodityService;
import com.admin.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 二级列表 前端控制器
 * </p>
 *
 * @author 零
 * @since 2022-12-13
 */
@RestController
@RequestMapping("/admin/commodity")
public class MobileEndCommodityController {
    @Autowired
    private MobileEndCommodityService commodityService;

    /**
     * 点击一级商品名 通过一级商品id获取该一级商品下的所有二级商品信息
     * @param pid 一级商品id
     * @return R
     */
    @GetMapping("list/{pid}")
    public R getCommoditys(@PathVariable("pid") Long pid){
        QueryWrapper<MobileEndCommodity> wrapper = new QueryWrapper<>();
        wrapper.eq("Mobile_end_Product_List_id",pid);
        List<MobileEndCommodity> list = commodityService.list(wrapper);
        if (list.size()>0){
            return R.ok().data("items",list);
        }
        return R.error();
    }
}

